﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class fairy : Form
    {
        static int TimerCD;
        static int minutes;
        public fairy()
        {
            InitializeComponent();
            TimerCD = 0;
            minutes = 0;
        }

        private void Tmr_Tick_Tick(object sender, EventArgs e)
        {
            if (minutes > 0)
            {
                minutes--;
            }
            else
            {
                if (TimerCD > 0)
                {
                    TimerCD--;
                    minutes = 60;
                }
            }


            lblTimerCd.Text = string.Format("{0:D2}", TimerCD) + ":" + string.Format("{0:D2}", minutes);
            lblTimerCd.Font = new Font("宋体", 26, FontStyle.Bold);
            lblTimerCd.ForeColor = Color.Green;

            if ((0 == TimerCD) && (0 == minutes))
            {
                Tmr_Tick.Enabled = false;
                lblTimerCd.BackColor = Color.Red;
                mtxtSetTimer.Show();
                btnSetTimer.Show();
            }
        }

        private void btnSetTimer_Click(object sender, EventArgs e)
        {
            int timerCD;
            if (int.TryParse(mtxtSetTimer.Text, out timerCD))
            {
                Tmr_Tick.Enabled = true;
                lblTimerCd.BackColor = fairy.DefaultBackColor;
                /*Color.FromArgb(240, 240, 240);*/
                minutes = 0;
                TimerCD = timerCD;
                mtxtSetTimer.Clear();
                mtxtSetTimer.Hide();
                btnSetTimer.Hide();
            }
            else
            {
                MessageBox.Show(this, "Input is invalid.");
                mtxtSetTimer.Clear();
            }
        }
    }
}
